#!/usr/bin/env python

import RPi.GPIO as GPIO
import time
import ping

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)
GPIO.setup(1, GPIO.IN)   #P1
GPIO.setup(7, GPIO.OUT)  #P7
GPIO.setup(22, GPIO.OUT) #P6

def Start(numTimes,speed):
    is_online = False
    start = True
    while start:
        try:
            is_online = ping.do_one('192.168.12.1',1)
        except:
            is_online = False
        time.sleep(speed)
    	if is_online:
    	    GPIO.output(7, True)
            if GPIO.input(1):
                GPIO.output(22, True)
            else:
                GPIO.output(22, False)
    	else:
            GPIO.output(22, False)
    	    while not is_online: 
    	        GPIO.output(7, True)
                time.sleep(speed)
                GPIO.output(7, False)
                time.sleep(speed)
                try:
                    is_online = ping.do_one('192.168.12.1',1)
                except:
                    is_online = False
    GPIO.cleanup()

Start(1, 1)


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
